package com.arron.principle.ocp;

public class Ocp {
    public static void main(String[] args) {
        GraphicEditor editor = new GraphicEditor();
        editor.drawCircle(new Circle());
        editor.drawRectangle(new Rectangle());
        editor.drawSquare(new Square());
    }
}

class GraphicEditor{
    public void drawShape(Shape s){
        if(s.m_type==1)
            drawRectangle(s);
        if(s.m_type==2)
            drawCircle(s);
        if(s.m_type==3)
            drawSquare(s);
    }

    public void drawRectangle(Shape r){
        System.out.println("绘制矩形");
    }
    public void drawCircle(Shape c){
        System.out.println("绘制圆形");
    }
    public void drawSquare(Shape c){
        System.out.println("绘制方形");
    }
}

class Shape{
    int m_type;
}

class Rectangle extends Shape{
    public Rectangle() {
        super.m_type=1;
    }
}

class Circle extends Shape{
    public Circle() {
        super.m_type=2;
    }
}

//新增加方形类
class Square extends Shape{
    public Square() {
        m_type=3;
    }
}


